package com.example.administrator.managesystem.view;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.managesystem.R;
import com.example.administrator.managesystem.adapter.GridCameraAdapter;
import com.example.administrator.managesystem.adapter.GridViewAdapter;
import com.example.administrator.managesystem.bean.CameraListBean;
import com.example.administrator.managesystem.bean.GetCameraBean;
import com.example.administrator.managesystem.ui.AddLandView;

import java.util.ArrayList;
import java.util.List;

public class ChooseCameraDialog extends Dialog{
    private GridView camera_gv;
    private ImageView delete;
    private GridCameraAdapter gridViewAdapter;
    private Context context;
    private List<CameraListBean.DataBean> camera_list;
    private AddLandView addLandView;

    //构造方法
    public ChooseCameraDialog(Context context, final AddLandView addLandView) {

        //设置对话框样式
        super(context, R.style.edit_AlertDialog_style);
        this.addLandView=addLandView;
        this.context=context;
        //通过LayoutInflater获取布局
        final View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_choose_camera, null);
        camera_gv=view.findViewById(R.id.camera_gv);
        delete=view.findViewById(R.id.dialog_delete);
        setContentView(view);  //设置显示的视图

        camera_gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                addLandView.showUrl(camera_list.get(position).getUrl(),camera_list.get(position).getDevice_number());

            }
        });


    }
    public void addCameraList(List<CameraListBean.DataBean> list){
        camera_list=list;
        gridViewAdapter = new GridCameraAdapter(context);
        gridViewAdapter.addDatas(camera_list);
        camera_gv.setAdapter(gridViewAdapter);
    }
    //取消监听
    public void setOnCancelListener(View.OnClickListener listener) {
        delete.setOnClickListener(listener);
    }

}
